package com.shfl.controller;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import stock.Stock;

import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.ResourceBundle;

public class LoginController  implements Initializable {


    @FXML
    private  PasswordField password ;

    @FXML
    private Button login;

    @FXML
    private TextField userName;

    public void initialize(URL location, ResourceBundle resources) {

        this.login.setOnAction(event -> {
            SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
            System.out.println(formatDateTime(myFormat.format(new Date())).toString());
            String password = this.password.getText();
            String passWord1 = formatDateTime(myFormat.format(new Date())).toString();
            if(password.equals("123456")){
                try {
                    changeWindow();
                } catch (Exception e) {

                    e.printStackTrace();
                }
            }
        });
    }
    public static void main(String[] args) {
        SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(formatDateTime(myFormat.format(new Date())).toString());//express_code //expressCode
    }
    public static Long formatDateTime(String strDateTime) {
        strDateTime = strDateTime+" 00:00:00";
        if(strDateTime.endsWith("1")){
            strDateTime = strDateTime+" 11:11:11";
        }
        if(strDateTime.endsWith("2")){
            strDateTime = strDateTime+" 22:22:22";
        }
        if(strDateTime.endsWith("3")){
            strDateTime = strDateTime+" 23:33:33";
        }

        if (strDateTime == null || "".equals(strDateTime)) {
            return null;
        } else {
            SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
                Date myDate = myFormat.parse(strDateTime.trim());
                return myDate.getTime();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    }

    public void changeWindow(){
        try {
            Stock.convertImageMain.showWindow();
            Stock.LOGIN_STAGE.hide();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
